events {
  worker_connections  1024;
}
http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
  access_log  /var/log/nginx/access.log  main;
  upstream api_servers {
    server flask1:5001;
    server flask2:5002;
  }
  server {
    listen 443 ssl;
    server_name flask;

    ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;

    location / {
      proxy_pass http://api_servers;
      # proxy_ssl_server_name on;
      # proxy_set_header        Host $host;
      # proxy_ssl_trusted_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
      # proxy_ssl_verify       on;
      # proxy_ssl_verify_depth 2;
    }
  }
  server {
    listen 80;
    server_name flask;

    return 301 https://$server_name$request_uri;
  }
}
